package behavior;

/**
 * Utility class that converts a robots current heading, new heading and position
 * into a standardized array of commands that can be interpreted by the robots.
 * This is necessary because of the limitations of data transfer between the
 * robots and the host computer.
 *
 * @author      Gabriel Loewen
 * @author      James Weston
 * @author      Jackie O'Quinn
 */
public class Util {

    /**
     * Defaul constructor
     */
    public Util() {
    }

    /**
     * Returns a standardized int array formatted so that the robot can understand
     * the command.
     *
     * @param   robotHeading    The robots current heading
     * @param   robotX          The robots current x position
     * @param   robotY          The robots current y position
     * @param   direction       The new heading for the robot
     */
    public static int[] getMoveData(char robotHeading, int robotX, int robotY, char direction) {
        switch (robotHeading) {
            case 'N':
                switch (direction) {
                    case 'N':
                        robotY++;
                        break;
                    case 'S':
                        robotY--;
                        break;
                    case 'E':
                        robotX++;
                        break;
                    case 'W':
                        robotX--;
                        break;
                }
                break;
            case 'S':
                switch (direction) {
                    case 'N':
                        robotY++;
                        break;
                    case 'S':
                        robotY--;
                        break;
                    case 'E':
                        robotX++;
                        break;
                    case 'W':
                        robotX--;
                        break;
                }
                break;
            case 'E':
                switch (direction) {
                    case 'N':
                        robotY++;
                        break;
                    case 'S':
                        robotY--;
                        break;
                    case 'E':
                        robotX++;
                        break;
                    case 'W':
                        robotX--;
                        break;
                }
                break;
            case 'W':
                switch (direction) {
                    case 'N':
                        robotY++;
                        break;
                    case 'S':
                        robotY--;
                        break;
                    case 'E':
                        robotX++;
                        break;
                    case 'W':
                        robotX--;
                        break;
                }
                break;
        }
        return new int[]{direction, robotX, robotY};
    }
}
